package cn.chenhuanming.shh.administer.intermediary.business.eventHandler;

import cn.chenhuanming.shh.administer.entity.jpa.HouseOrderApply;
import cn.chenhuanming.shh.administer.repository.HouseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import org.springframework.stereotype.Component;

/**
 * Created by chenhuanming on 2017-08-21.
 *
 * @author chenhuanming
 */
@Component
@RepositoryEventHandler
public class HouseOrderApplyEventHandler {

    @Autowired
    HouseRepository houseRepository;

    @HandleBeforeCreate
    public void beforeCreate(HouseOrderApply houseOrderApply){
        if(houseOrderApply.getHouse()==null)
            throw new IllegalArgumentException("预约的房源不能为空");
        houseOrderApply.setUserBroker(houseOrderApply.getHouse().getUserBroker());
        houseOrderApply.setStatus("正常");
        houseOrderApply.setOrderStatus("预约中");
    }
}
